package org.blame;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.List;

public class JedisDemoList {
    public static void main(String[] args) {
        JedisPool jedisPool=new JedisPool("tcp://127.0.0.1:8888");
        try(Jedis jedis=jedisPool.getResource()){
//            test1(jedis);
//            test2(jedis);
//            test3(jedis);
//            test4(jedis);
//            test5(jedis);
            test6(jedis);

        }
    }
    public static void test6(Jedis jedis){
        jedis.flushAll();
        jedis.lpush("k","111","222","333");
        long k = jedis.llen("k");
        System.out.println(k);
    }

    public static void test5(Jedis jedis){
        jedis.flushAll();
//        jedis.lpush("key","1");

        List<String> key = jedis.blpop(100, "key");
        System.out.println(key);

    }
    public static void test4(Jedis jedis){
        jedis.flushAll();
        jedis.lpush("k","111","222","333");
//        尾删
        String k = jedis.rpop("k");
        System.out.println(k);
        k = jedis.rpop("k");
        System.out.println(k);
        k = jedis.rpop("k");
        System.out.println(k);
        k = jedis.rpop("k");
        System.out.println(k);
        System.out.println(jedis.get("k"));


    }
    public static void test3(Jedis jedis){
        jedis.flushAll();
        jedis.lpush("k","111","222","333");
//        头删
        String k = jedis.lpop("k");
        System.out.println(k);
        k = jedis.lpop("k");
        System.out.println(k);
        k = jedis.lpop("k");
        System.out.println(k);
        k = jedis.lpop("k");
        System.out.println(k);
        System.out.println(jedis.get("k"));


    }
    public static void test2(Jedis jedis){
        jedis.flushAll();
//        尾插
        long k = jedis.rpush("k", "12", "21", "21", "44");
        System.out.println(k);
        List<String> k1 = jedis.lrange("k", 0, -1);
        System.out.println(k1);
    }
    public static void test1(Jedis jedis){
        jedis.flushAll();
//        头插
        long k = jedis.lpush("k", "12", "21", "21", "44");
        System.out.println(k);
        List<String> k1 = jedis.lrange("k", 0, -1);
        System.out.println(k1);
    }
}
